package com.ubs.web.server;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.ubs.dom.Account;
import com.ubs.ejb.AccountControllerLocal;
import com.ubs.web.client.service.ProtalService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class PortalServiceImpl extends RemoteServiceServlet implements
		ProtalService {

	public AccountControllerLocal getAccountControllerBean() {
		InitialContext ic;
		try {
			ic = new InitialContext();
			return (AccountControllerLocal) ic.lookup("ubs/AccountController");
		} catch (NamingException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public void registerAccount(Account account)
			throws IllegalArgumentException {
		
		AccountControllerLocal bean = getAccountControllerBean();
		bean.registerAccount(account);
	}

	@Override
	public Account loginAccount(String login, String passwordMD5)
			throws IllegalArgumentException {
		
		AccountControllerLocal bean = getAccountControllerBean();
		return bean.loginAccount(login, passwordMD5);
	}
}
